package com.bdcom.nms.NmsCollect.dao.impl;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

import org.springframework.stereotype.Repository;

import com.bdcom.nms.NmsCollect.dao.ManagedObjectDao;
import com.bdcom.nms.NmsCollect.pojo.ManagedObject;

@Repository("managedobjdao")
public class ManagedObjectDaoImpl implements ManagedObjectDao{
	
	@PersistenceContext
	private EntityManager enmanager;
	
	@Override
	public List<ManagedObject> findByClassName(String classname) {
		// TODO Auto-generated method stub
//		/**
//		 * 用criteria的查询方式
//		 */
//		CriteriaBuilder cbuilder=enmanager.getCriteriaBuilder();
//		
//		CriteriaQuery<ManagedObject> cquery=cbuilder.createQuery(ManagedObject.class);
//		
//		Root<ManagedObject> mo=cquery.from(ManagedObject.class);
//		
//		Predicate pdicate=cbuilder.equal(mo.get("classname"), classname);
//		
//		cquery.where(pdicate);
//		
//		TypedQuery<ManagedObject> tquery=enmanager.createQuery(cquery);
//		
//		return tquery.getResultList();
		
		/**
		 * JPQL
		 */
//		TypedQuery<ManagedObject> jpquery =enmanager.createQuery("From ManagedObject M WHERE  M.type =?1", ManagedObject.class);
		
		TypedQuery<ManagedObject> jpquery =enmanager.createQuery("SELECT M From ManagedObject M WHERE  M.classname =?1", ManagedObject.class);
		
		jpquery.setParameter(1, classname);
		
		return jpquery.getResultList();
		
	}

}
